Code Golf
Code Golf is a competitive coding exercise in which esoteric languages are used to write arbitrary scripts ("holes") in as few characters/bytes ("strokes") as possible. It is named in analogy to the traditional physical golf , where the aim is to sink a ball in as few physical strokes as possible. MATL One Code Golf language that is popular today is MATL , based on MATLAB . MATL can be tested online at this link . Some pre-literature on the functions is contained here, while a full list can be found in Luis Mendo's introduction to the language on page 31, erroneously simplified belowNB: each function has four columns in the source document, corresponding to it behaving alone, or with "X","Y" or "Z" preceding it.: Examples: (search Luis Mendo's CodeStack history) From EsoLangs.org : The Fibonnacci sequence can be generated up to input "n", with just 10 characters: 1ti2-:"yy+ 1 % number literal t % duplicate top element i % input number n 2 % number literal - % subtract. Produces n-2 : % vector of equally spaced values: 2, ... , n-2 " % for loop. There will be n-2 iterations y % duplicate second-top element y % duplicate second-top element + % addition of top two elements % implicitly end for loop % implicitly display stack contents, bottom to top A simple adding puzzle from the Code Golf Stack Exchange: Taking inputs "b", the code "s" is enough to perform "a+b" in 1 byte. Using randomised loops to print a string a stochastic number of times: The code "`G@QYrq]x" is enough to fulfill this puzzle in 9 bytes: ` % Do...while G % Push input @ % Push iteration index k, starting at 1 QYrq % Random integer uniformly distributed in {0, 1, ..., k}. This is the % loop condition. If non-zero (which occurs with probability k/(1+k)) % proceed with next iteration; else exit loop ] % End x % Delete, as there are one too many strings. Implicitly display the stack The reason that the code terminates for the case when 'QYrq' produces a 0 is that "do...while" loops are boolean by default. Tips: Know the predefined literals : *F, pushes 0 (actually False) *T, pushes 1 (actually True) *H, pushes 2 (predefined clipboard value) *I, pushes 3 (predefined clipboard value) *K, pushes 4 (predefined clipboard value) *J, pushes 0 + 1j (predefined clipboard value) The value of these is that they save the need to separate numbers with a space (" "). If you wish to push "1" then "4", "14" will be misinterpretted as the number fourteen, while "1K" or "TK" or "T4" will all solve this in two characters (as opposed to "1 4"). Jelly One of the most popular golfing languages. Avaliable at Dennis Mitchell's GitHub. Examples: Testing for Ramunajan-esque numbers (sum of 2 cubes in 2 ways): R*3<Ðf⁸ŒċS€ċ⁸>1 Try it here. Here, the code takes the range 1:N (R-command) and exponentiates (*) each number to the power 3, creating an array of cubes up to N^3. The "<" command then highlights all cubes less than 1729 and the "Ðf" command filters them out. (See here for code up to this point) Next, the "⁸Œċ" term starts collecting pairs of these cubes into 1x2 arrays (e.g. 1, 8,...1, 8,...,1728,1,8,...,1728). The "S€" term performs sums amongst each of these pairs, forming all the possible cube sums of relevant cubes. The "ċ" then counts how many times the input value appears in these sums. Lastly, the "⁸>1" term ensures that the number can be formed from at least 2 different sums, completing the problem (in 15 bytes/characters). Code to parse Astrotheme html source into lists of Celebrities on the page competition to solve it Tips: List of "Atoms" (or built-in links) List of "Quicks" (commands to parser) References Category:Information Age Category:Programming Category:Entropy Category:Information Theory